unit WaitForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, LMDControl, LMDCustomControl, LMDBiProgressBar;

type
  TWaitFrm = class(TForm)
    Timer1: TTimer;
    BreakBtn: TButton;
    InfoLabel: TLabel;
    PBar: TLMDBiProgressBar;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
    Function Wait(del:word; Msg:ShortString=''; triggPoint:Pointer=nil; HideBtn:boolean=false):boolean;overload;
    Function Wait(del:word; Msg:ShortString=''; TestVar:Pointer=nil; BreakVal:double=0.0; HideBtn:boolean=false):boolean;overload;
  end; {type}

var
  WaitFrm: TWaitFrm;
  trigger: ^boolean;
  BreakVar:^double;
  BreakValue:double;

implementation

{$R *.DFM}


procedure TWaitFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  trigger:= nil;
  BreakValue:=0.0;
  BreakVar:=nil;
  Timer1.Enabled:= false;
  PBar.DarkValue:=0;
  PBar.Marquee:= true;
end;


procedure TWaitFrm.FormCreate(Sender: TObject);
begin
  trigger:= nil;
end; {proc}


Function TWaitFrm.Wait(del:word; Msg:ShortString=''; triggPoint:Pointer=nil; HideBtn:boolean=false):boolean;
begin
  BreakBtn.Visible:= not HideBtn;
  if del<>0 then
    begin
      Timer1.Interval:= del*1000;
      Timer1.Enabled:= true;
      ModalResult:= MrOk;
      InfoLabel.Caption:= Msg;
      ShowModal;
      exit;
    end; {if}

  if triggPoint<>nil then
    begin
      trigger:= triggPoint;
      Timer1.Interval:= 1000;
      Timer1.Enabled:= true;
      ModalResult:= MrNone;
      InfoLabel.Caption:= Msg;
      ShowModal;
      exit;
    end; {if}
end; {func}


Function TWaitFrm.Wait(del:word; Msg:ShortString=''; TestVar:Pointer=nil; BreakVal:double=0.0; HideBtn:boolean=false):boolean;
begin
  BreakBtn.Visible:= not HideBtn;
  if del<>0 then
    begin
      Timer1.Interval:= del*1000;
      Timer1.Enabled:= true;
      ModalResult:= MrOk;
      InfoLabel.Caption:= Msg;
      ShowModal;
      exit;
    end; {if}

  if TestVar<>nil then
    begin
      BreakVar:= TestVar;
      BreakValue:= BreakVal;
      Timer1.Interval:= 1000;
      Timer1.Enabled:= true;
      ModalResult:= MrNone;
      InfoLabel.Caption:= Msg;
      PBar.Marquee:= false;
      PBar.Scale:= TRUNC(BreakValue);
      ShowModal;
      exit;
    end; {if}

end; {func}



procedure TWaitFrm.Timer1Timer(Sender: TObject);
begin
  if trigger<>nil then
    begin
      if trigger^ then
       begin
         Timer1.Enabled:= false;
         ModalResult:= MrOk;
         trigger:= nil;
         Close;
        end; {if}
      exit;
    end; {if}

  if BreakVar<>nil then
    begin
      PBar.DarkValue:= TRUNC(BreakVar^);
      if BreakVar^>=BreakValue then
       begin
         Timer1.Enabled:= false;
         ModalResult:= MrOk;
         BreakVar:= nil;
         PBar.Marquee:= true;
         Close;
        end; {if}
      exit;
    end; {if}

  Timer1.Enabled:= false;
  Close;
  ModalResult:= mrOk;
end; {proc}


end.
